home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-15 | 8.5 KB | 276 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UProgressIndicators.h
- // ETO20 MacApp 3.3.1, MPW 3.4.1
- // Copyright ©1995-1996 Conrad Kopala
- // Twist Down Lists version 2.0a0 7/15/96
- //Reference: A Reassuring Progress Indicator for MacApp by James Plamodon
- //FrameWorks Volume 5, Number 3, June 1991, page 46
- //----------------------------------------------------------------------------------------
- /*
- Instructions for use of TProgressBarIndicator
-
- Add the following fields to the TYourObject that will be using the TProgressBarIndicator;
- TProgressBarIndicator* fProgressBarIndicator;
- long fUpdateAmount;
- long fProgressUpdateCounter;
-
- In TYourObject::TYourObject() initialze them as follows:
- fProgressBarIndicator = NULL;
- fUpdateAmount = 0;
- fProgressUpdateCounter = 0;
-
- In the method of TYourObject that uses TProgressBarIndicator insert the following code:
-
- CStr255 itsOperationString;
- GetIndString(itsOperationString, kProgressIndicatorOperationStrings, 3);
-
- CStr255 itsSubjectString = fVolumeName;
- fProgressBarIndicator = NewProgressBarIndicator(itsOperationString, itsSubjectString);
-
- this -> AddDependent(fProgressBarIndicator);
- fProgressBarIndicator -> PrepareToStart(TRUE);
-
- long barLength = fProgressBarIndicator -> GetBarLength();
-
- //The default value for fUpdateAmount is set to 1.
- //Unfortunately, if there are a lot of items to read and the progress bar is updated each time
- //an item is read, it takes a long time to populate the list. With the following if statement,
- //the update amount is adjusted so that the progress bar is updated only when enough
- //progress has been made to update it by at least one pixel. This noticibly speeds things up.
- //Comment out the following if statement and see for yourself.
-
- if (fNumberOfItemsToLoad > barLength)
- {
- long updateAmount = fNumberOfItemsToLoad/barLength;
- this -> SetUpdateAmountTo(updateAmount);
- }
-
- progressUpdateCounter = 0;
-
- fProgressBarIndicator -> Start(fNumberOfItemsToLoad);
-
- You are now ready to use fProgressBarIndicator.
-
- In the loop which does whatever is being done insert the following code:
-
- do
- {
- ++fProgressUpdateCounter;
- if (fProgressUpdateCounter >= fUpdateAmount)
- {
- fProgressUpdateCounter = 0;
- this -> Changed(mUpdateProgressBar, this);
- this -> SetChangeCount(0); //If this refers to a TDocument, changed sets fChangeCount to
- //a positive value which will result in an attempt to save the
- //document when it is closed and if you don't want that,
- //set fChangecount to zero here. Or, override TDocument::Changed
- //and don't call the inherited method.
- }
-
- }
- while (fProgressBarIndicator -> IsStopped() == FALSE);
-
- Whe you're done with fProgressBarIndicator, get rid of it:
- if (fProgressBarIndicator != NULL)
- {
- fProgressBarIndicator -> Stop();
- this -> RemoveDependent(fProgressBarIndicator);
- fProgressBarIndicator = (TProgressBarIndicator*)FreeIfObject(fProgressBarIndicator);
- }
- */
-
-
- #ifndef __UPROGRESSINDICATORS__
- #define __UPROGRESSINDICATORS__
-
- //MacApp stuff
- /*
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
- */
- #ifndef __UCONTROL__
- #include "UControl.h"
- #endif
-
- #ifndef __UDIALOG__
- #include "UDialog.h"
- #endif
-
- #ifndef __UDIALOGBEHAVIOR__
- #include "UDialogBehavior.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- //ToolBox stuff
- //None
-
- //ANSI stuff
- //None
-
- //----------------------------------------------------------------------------------------
- // Constants
- //----------------------------------------------------------------------------------------
- const ResNumber kProgressIndicatorOperationStrings = 1003;
- const IDType kProgressBarBehavior = 'pBar';
-
- //----------------------------------------------------------------------------------------
- // Forward and external classes
- //----------------------------------------------------------------------------------------
- class TProgressBar; //forward
- class TProgressView; //forward
-
- //----------------------------------------------------------------------------------------
- // TProgressBarIndicator
- //----------------------------------------------------------------------------------------
-
- class TProgressBarIndicator: public TObject
- {
- MA_DECLARE_CLASS;
-
- public:
- long fMax;
- long fCurrent;
- Boolean fStopped;
- TWindow* fProgressWindow;
- TProgressView* fProgressView;
- CStr255 fOperationString;
- CStr255 fSubjectString;
- long fUpdateAmount;
-
- TProgressBarIndicator::TProgressBarIndicator();
- virtual ~TProgressBarIndicator();
-
- virtual void TProgressBarIndicator::IProgressBarIndicator(const CStr255& operationString, const CStr255& subjectName);
- void TProgressBarIndicator::CreateProgressWindow();
-
- virtual void TProgressBarIndicator::Continue();
-
- virtual void TProgressBarIndicator::DoUpdate(ChangeID theChange,
- TObject* changedObject, TObject* changedBy,TDependencySpace* dependencySpace);
-
- virtual void TProgressBarIndicator::PrepareToStart(Boolean redraw);
- virtual void TProgressBarIndicator::Reset();
- virtual void TProgressBarIndicator::Start(long max);
- virtual void TProgressBarIndicator::Stop();
- virtual Boolean TProgressBarIndicator::IsStopped();
- virtual void TProgressBarIndicator::DoContinue(long howMuch);
- virtual void TProgressBarIndicator::DrawAtOnce(Boolean wholeThing);
-
- virtual Boolean TProgressBarIndicator::WasCancelled();
- long TProgressBarIndicator::GetBarLength();
- void TProgressBarIndicator::SetUpdateAmountTo(long updateAmount);
- };
-
- //----------------------------------------------------------------------------------------
- // TProgressDialogBehavior
- //----------------------------------------------------------------------------------------
-
- class TProgressDialogBehavior: public TDialogBehavior
- {
- MA_DECLARE_CLASS;
-
- public:
-
- TProgressDialogBehavior::TProgressDialogBehavior();
- virtual ~TProgressDialogBehavior();
-
- void TProgressDialogBehavior::IProgressDialogBehavior(Boolean isModal,IDType itsDefaultItem,IDType itsCancelItem);
- Boolean TProgressDialogBehavior::WasCancelled();
-
-
- };
-
- //----------------------------------------------------------------------------------------
- // TProgressWindow
- //----------------------------------------------------------------------------------------
-
- class TProgressWindow: public TWindow
- {
- MA_DECLARE_CLASS;
-
- public:
- TProgressWindow::TProgressWindow();
- virtual ~TProgressWindow();
-
- void TProgressWindow::IProgressWindow(TDocument* itsDocument,WindowPtr itsWMgrWindow,
- Boolean canResize,Boolean canClose,Boolean disposeOnFree);
-
-
-
-
- };
- //----------------------------------------------------------------------------------------
- // TProgressView
- //----------------------------------------------------------------------------------------
-
- class TProgressView: public TView
- {
- MA_DECLARE_CLASS;
-
- public:
- TProgressBar* fProgressBar;
- TButton* fStopButton;
-
- TProgressView::TProgressView();
- virtual ~TProgressView();
-
- void TProgressView::IProgressView(TDocument* itsDocument,TView* itsSuperView,
- const VPoint& itsLocation,const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,SizeDeterminer itsVSizeDet);
-
- void TProgressView::Continue(long howMuch);
- void TProgressView::DrawAtOnce(Boolean redraw);
- void TProgressView::PrepareToStart(Boolean redraw);
- void TProgressView::Reset();
- void TProgressView::Start(long max);
- void TProgressView::Stop();
- long TProgressView::GetBarLength();
- };
- //----------------------------------------------------------------------------------------
- // TProgressBar
- //----------------------------------------------------------------------------------------
-
- class TProgressBar: public TControl
- {
- MA_DECLARE_CLASS;
-
- public:
- long fMax;
- long fCurrent;
- VRect fBarRect;
- PenState fPen;
-
- TProgressBar::TProgressBar();
- virtual ~TProgressBar();
- void TProgressBar::IProgressBar(TView* itsSuperView,const VPoint& itsLocation,const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,SizeDeterminer itsVSizeDet,const TextStyle& itsTextStyle);
-
- void TProgressBar::SetBarSize();
- void TProgressBar::SetPen();
- virtual void TProgressBar::Draw(const VRect& area);
-
- void TProgressBar::Continue(long howMuch);
- void TProgressBar::Reset();
- void TProgressBar::Start(long max);
- void TProgressBar::Stop();
- long TProgressBar::GetBarLength();
- };
-
- //----------------------------------------------------------------------------------------
- // Global initialization procedure
- //----------------------------------------------------------------------------------------
-
-
- extern void InitUProgressDialog();
- extern TProgressBarIndicator* NewProgressBarIndicator(const CStr255& itsOperationString, const CStr255& itsSubjectString);
-
- #endif
-